<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/jquery.mini.js"></script>
</head>

<body>
    <!-- <form id="form" enctype=“multipart/form-data>
        <input type="file" name="file" id="file">
    </form> -->
    <form>
        <input type="file" id="file">
    </form>
    <img src="F:/upload/6ec8ea30301b4ad28373e5de4a278bcf.jpg" alt="">

</body>
<script>
    $(function () {
        // var formData = new FormData($("#form")[0]);//获取表单中的文件
        // $('#file').change(function () {
        //     $.ajax({
        //         url: "goods/uploadimg",
        //         data: formData,
        //         type: "post",
        //         processData: false,
        //         contentType: false,
        //         dataType: "json",
        //     success: function (result) {
        //         alert("成功");
        //         if (result.state === 200) {
        //             alert("goods_path" + result.data);
        //             goods_path = result.data;
        //         } else {
        //             alert("图片上传失败！");
        //         }
        //     },
        //     error: function (result) {
        //         alert(reult.state);
        //     }
        // });
        // })
        $("#file").change(function () {
            var file = $("#file")[0].files[0];
            var formData = new FormData();
            formData.append("file", file);
            $.ajax({
                url: "/goods/uploadimg",
                type: "POST",
                data: formData,
                dataType: "json",
                processData: false,	// 使数据不做处理
                contentType: false,		// 不要设置Content-Type请求头
                success: function (result) {
                    alert("成功");
                    if (result.state === 200) {
                        alert("goods_path" + result.data);
                        goods_path = result.data;
                    } else {
                        alert("图片上传失败！");
                    }
                },
                error: function (result) {
                    alert(reult.state);
                }
            });


        })
    })
</script>

</html>